OpenRoads Designer CONNECT Edition SDK Help

Corridor items feature definition set

Description

  • This is a custom interactive tool for setting feature definition to an alignment.
  • The user is prompted to select a horizontal alignment and feature definition name . The selected feature definition is then applied to an alignment.
  • The CorridorItemsCorridorCreator class extends DgnElementSetTool which handles different events to interact with UI, the CorridorItemsCorridorCreator class overrides the events here in this tool .

Remarks

  • This sample code is a part of ManagedSDKExample which you get with SDK installation under "examples" section in SDK installation directory.

  • If you encounter any error while using DgnElementSetTool class, make sure to add a reference to Bentley.DgnDisplayNet.dll by selecting Project > Add Reference or change the projects .csproj file to add reference to this dll .

  • The default dll location will be "C:\Program Files\Bentley\OpenRoads Designer CE 10.11\OpenRoadsDesigner\Bentley.DgnDisplayNet.dll".

  • The method OnDataButton() handles the horizontal alignment selection from User interface.

Source Code


//Required References
using System.Collections.Generic;
using Bentley.DgnPlatformNET;
using Bentley.DgnPlatformNET.Elements;
using Bentley.CifNET.GeometryModel.SDK;
using Bentley.CifNET.GeometryModel.SDK.Edit;

namespace ManagedSDKExample.Examples
{
    class CorridorItemsFeatureDefinitionSet : DgnElementSetTool
    {
        private string m_featureDefinition = null;
        private string m_featureName = null;
        /*----------------------------------------------------------------------------------------------**/
        /* Write Function | The user is prompted to select a horizontal alignment and select a feature definition.
         *                  Then the feature definition will set to the vertical alignment.
        /*--------------+---------------+---------------+---------------+---------------+----------------*/

        private void SetFeatureDefinition(Bentley.DgnPlatformNET.Elements.Element element)
        {
            Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit con = Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit.GetActive();
            Alignment alignmentEdit = Alignment.CreateFromElement(con, element);
            if (alignmentEdit.DomainObject == null)
                return;
            con.StartTransientMode();
            //sets feature definition and feature name
            if (m_featureDefinition != null && m_featureDefinition != string.Empty)
            {
                alignmentEdit.SetFeatureDefinition(m_featureDefinition, m_featureName);
            }
            con.PersistTransients();
        }

        private void GetFeatureDefinition()
        {
            List<string> featureNames = new List<string>();
            Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit con = Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit.GetActive();
            FeatureDefinitionManager fdm = FeatureDefinitionManager.Instance;
            featureNames.AddRange(fdm.GetFeatureDefinitions(con, "Alignment"));
            featureNames.Sort();
            m_featureDefinition = featureNames[0];
            //m_featureDefinition = "Alignment\\Geom_Baseline";
            m_featureName = "GeomBL";

        }

        protected override void OnPostInstall()
        {
            base.BeginPickElements();
            Bentley.DgnPlatformNET.AccuSnap.LocateEnabled = true;
            Bentley.DgnPlatformNET.AccuSnap.SnapEnabled = true;
            base.OnPostInstall();
            NotificationManager.OutputPrompt("Select a horizontal alignment.");
        }

        protected override bool OnDataButton(Bentley.DgnPlatformNET.DgnButtonEvent ev)
        {
            HitPath hitPath = DoLocate(ev, true, 1);
            if (hitPath == null)
                return false;
            Bentley.DgnPlatformNET.Elements.Element selectedElement = hitPath.GetHeadElement();
            if (selectedElement != null)
            {
                GetFeatureDefinition();
                SetFeatureDefinition(selectedElement);
                NotificationManager.OutputPrompt("Command complete. Select a new horizontal alignment or right click to exit the command.");
                return true;
            }
            return false;
        }

        public static void InstallNewInstance()
        {
            CorridorItemsFeatureDefinitionSet tool = new CorridorItemsFeatureDefinitionSet();
            tool.InstallTool();
        }

        protected override bool OnResetButton(DgnButtonEvent ev)
        {
            ExitTool();
            return true;
        }

        protected override void OnRestartTool()
        {
            InstallNewInstance();
        }

        public override StatusInt OnElementModify(Element element)
        {
            return Bentley.DgnPlatformNET.StatusInt.Error;
        }

    }
}